package com.tmzn.jwt;

import com.tmzn.jwt.bean.MyIJwtAble;
import com.tmzn.redis.RedisCache;
import com.tmzn.util.SpringUtils;

public class JwtStore {

	private RedisCache redisCache;


	public JwtStore(){
		this.redisCache = SpringUtils.getBean(RedisCache.class);
	}

	public void set(String userName, MyIJwtAble user) {
		redisCache.setCacheObject(userName,user);
		
	}

	public MyIJwtAble get(String userName) {
		Object cacheObject = redisCache.getCacheObject(userName);
		return (MyIJwtAble)cacheObject;
	}

	/**
	 * 获取过期时间
	 * @param userName
	 * @return
	 */
	public Long ttl(String userName) {
		Long ttl = redisCache.getExpire(userName);
		return ttl;
	}

	/**
	 * 设置过期时间
	 * @param userName
	 * @param time
	 */
	public void expire(String userName,int time){
		redisCache.expire(userName, time);
	}
	
	public void del(String userName){
		redisCache.deleteObject(userName);
	}
	
}
